package com.jch.string_decoder;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

import java.text.SimpleDateFormat;
import java.util.Date;

public class DemoServerHandler extends ChannelInboundHandlerAdapter {

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        System.out.println("连接报告开始");
        System.out.println("有一个客户端接入");
        System.out.println("HOST：" + ctx.channel().localAddress().toString());
        System.out.println("连接报告结束");
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        // 注意此处已经不需要自己解码了
        System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + " 接收到消息：" + msg);
        ctx.fireChannelRead(msg); // 将消息传递给下一个Handler进行处理
    }
}
